package com.orhon.smartcampus.modules.systemctl.mm;


import java.util.List;

import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import com.orhon.smartcampus.modules.base.mm.DictionaryMapper;
import com.orhon.smartcampus.modules.base.mm.LangMapper;
import com.orhon.smartcampus.modules.systemctl.entity.Menus;
import com.orhon.smartcampus.modules.systemctl.gqlModel.GQLMenus;


@Mapper(uses = {
        DictionaryMapper.class,
        LangMapper.class,
        ModuleMapper.class
})
public interface MenuMapper {

    MenuMapper MAPPER = Mappers.getMapper(MenuMapper.class);

    @Mapping(source = "id" , target = "id")
    @Mapping(source = "title" , target = "title")
    @Mapping(source = "name" , target = "name")
    @Mapping(source = "path" , target = "path")
    @Mapping(source = "component" , target = "component")
    @Mapping(source = "category" , target = "category", qualifiedByName = "str2dic")
    @Mapping(source = "type" , target = "type", qualifiedByName = "str2dic")
    @Mapping(source = "level" , target = "level")
    @Mapping(source = "meta" , target = "meta")
    @Mapping(source = "clients" , target = "clients", qualifiedByName = "StringToList")
    @Mapping(source = "icon" , target = "icon")
    @Mapping(source = "ordered" , target = "ordered")
    @Mapping(source = "status" , target = "status")
    @Mapping(source = "createdAt" , target = "created_at")
    @Mapping(source = "updatedAt" , target = "updated_at")
    @Mapping(source = "deletedAt" , target = "deleted_at")
    @Mapping(target = "module" , ignore = true)
    @Mapping(target = "parent" , ignore = true)
    @Mapping(target = "childreen" , ignore = true)
    @Mapping(target = "widgets" , ignore = true)
    @Mapping(target = "parent_id" , source = "parent_id")
    @Mapping(target = "module_id" , source = "module_id")
    GQLMenus toMenus(Menus entity);
    
    @InheritConfiguration(name = "toMenus")
    List<GQLMenus> toMenusList(List<Menus> entities);


    @AfterMapping
    default void processParentId(Menus menuEntity , @MappingTarget GQLMenus entity){
        //System.out.println(menuEntity);
        //System.out.println(entity);
        GQLMenus parent = this.toMenus(menuEntity.getMenus());
        entity.setParent(parent);
    }


}
